package train;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DAY626 {
    public static void main(String[] args) {
      String a="aa";
      String b="ab";
        System.out.println(canConstrucet(a, b));
    }
    public static String toLowerCase(String s){
        System.out.println("子静态");
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(chars[i]>='A'&&chars[i]<='Z'){
                chars[i]= (char) (chars[i]+32);
            }
        }
        return new String(chars);
    }

    //解码字母到整数映射
    public static String freqAlph(String s){
        StringBuffer buffer = new StringBuffer();
        int sum=0;
        int i=0;
        for ( i = 0; i < s.length()-2; i++) {
            if(s.charAt(i+2)=='#'){
             sum=(s.charAt(i)-48)*10+(s.charAt(i+1)-48);
             buffer.append((char)('a'+(sum-1)));
             i=i+2;
            }else{
                buffer.append((char)('a'+(s.charAt(i)-49)));
            }
        }
        if(i>s.length()) return buffer.toString();
        else {
            if(s.charAt(s.length()-2)!='#'){
                buffer.append((char)('a'+(s.charAt(s.length()-2)-49)));
                buffer.append((char)('a'+(s.charAt(s.length()-1)-49)));
            }else buffer.append((char)('a'+(s.charAt(s.length()-1)-49)));
        }

        return buffer.toString();
    }

    //验证外星语
    public static boolean isAlien(String[] words,String order){
        for (int i = 0; i < words.length-1; i++) {
            int length=words[i].length()>words[i+1].length()?words[i+1].length():words[i].length();
            for (int j = 0; j < length; j++) {
                if(order.indexOf(words[i].charAt(j))>order.indexOf(words[i+1].charAt(j))) return false;
                if(order.indexOf(words[i].charAt(j))<order.indexOf(words[i+1].charAt(j))) break;
                else continue;
            }
          if(words[i].length()>words[i+1].length()&&words[i].contains(words[i+1])) return false;
        }

        return true;
    }

    //汇总区间
    public static List<String> summRange(int[] nums){
        List<String> list = new ArrayList<>();
        String s;
        int i;
        boolean k=true,temp=false;
        for ( i = 0; i < nums.length; i++) {
            s = nums[i] + "";
            while (i < nums.length-1) {
                if (nums[i + 1] == nums[i] + 1) {
                    i++;
                    temp = true;
                } else break;
            }
            if (temp)
                s = s + "->" + nums[i];

            list.add(s);
            temp = false;
        }
        return list;
    }

    //一个字符串是否包含另一个字符串
    public static boolean canConstrucet(String ransomNote,String magazine){
        char[] chars = ransomNote.toCharArray();
        char[] chars1 = magazine.toCharArray();
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < chars1.length; i++) {
            if(map.containsKey(chars1[i])){
                int a=map.get(chars1[i])+1;
                map.put(chars1[i],a);
            }else map.put(chars1[i],1);
        }
        for (int i = 0; i < chars.length; i++) {
            if(!map.containsKey(chars[i])) return false;
            else {

               int a= map.get(chars[i])-1;
               map.put(chars[i],a);
               if(a<0) return false;
            }
        }
        return true;
    }


}
